//
//  CInemaViewController.m
//  UI12豆瓣大项目
//
//  Created by dllo on 15/10/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "CInemaViewController.h"
#import "CinemaTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "AppTools.h"
#import "Activity.h"
#import "CinemaDViewController.h"
@interface CInemaViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,retain) UITableView *cinematableView;

@end

@implementation CInemaViewController
- (void)dealloc
{
    [_activityArray release];
    [_hub release];
    [_cinematableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"影院";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav"] forBarMetrics:UIBarMetricsDefault];
    
    self.cinematableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.cinematableView.delegate = self;
    self.cinematableView.dataSource = self;
    [self.view addSubview:self.cinematableView];
    
    //注册cell
    [self.cinematableView registerClass:[CinemaTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    //加载菊花
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"请耐心等待....";
    
    [AppTools getDataWithkey:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php" block:^(id result) {
//        NSLog(@"%@",result);
        NSMutableDictionary *Bigdic = result;
        NSString *reason = [Bigdic objectForKey:@"reason"];
        NSMutableDictionary *dic2 = [Bigdic objectForKey:@"result"];
        self.activityArray = [[NSMutableArray alloc] init];
        if ([reason isEqualToString:@"success"]){
            NSMutableArray *array = [dic2 objectForKey:@"data"];
            for (NSMutableDictionary  *dic in array) {
                Activity *activity = [[Activity alloc] init];
                [activity setValuesForKeysWithDictionary:dic];
                [self.activityArray addObject: activity];
                [activity release];
            }
        }else{
            NSLog(@"请求失败");
        }
        //刷新
        [self.cinematableView reloadData];
        //消除等待
        [self.hub hide:YES];
    }];
    [_cinematableView release];
    // Do any additional setup after loading the view.
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.activityArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellI = @"cell";
    CinemaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellI];
    Activity *activity = [self.activityArray objectAtIndex:indexPath.row];
    cell.activity = activity;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CinemaDViewController *cinemaDVC = [[CinemaDViewController alloc] init];
    Activity *activity = [self.activityArray objectAtIndex:indexPath.row];
    cinemaDVC.movieId = activity.movieId222;
    cinemaDVC.activity = activity;
    [self.navigationController pushViewController:cinemaDVC animated:YES];
    [cinemaDVC release];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140;
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
